



use   factor_pond ubigeo2019 using "$data_folder/censo17/CPV2017_POB.dta", clear  

bys ubigeo2019: egen pop_weighted_2017 = sum(factor_pond)
bys ubigeo2019: gen pop_unweighted_2017 = _N

keep pop_weighted_2017 pop_unweighted_2017 ubigeo2019
duplicates drop 

ren ubigeo2019 ubigeo 

replace pop_weighted_2017 = round(pop_weighted_2017)

sa "$data_folder/district_populations_2017.dta", replace 


import delimited  "$data_folder/fallecidos_covid.csv", clear  delimiter(";")


tostring fecha_fallecimiento, replace 

gen date = date(fecha_fallecimiento,"YMD")

format date %td

gen monthlyDate = mofd(date)
gen month = month(date)
gen year = year(date)

//keep june deaths
keep if month == 6 & year == 2020

gen june_deaths = 1 

collapse (count) june_deaths, by(ubigeo)

la var june_deaths "June 2020 Covid Deaths"



tostring ubigeo, replace 

replace ubigeo = "0" + ubigeo  if length(ubigeo) == 5
merge m:1 ubigeo using "$data_folder/district_populations_2017.dta", keep( 3 ) assert(2 3)

gen june_death_rate = june_deaths/pop_weighted_2017 * 100000


sa "$data_folder/covid_july_deaths.dta", replace 


